// import { ResultSetHeader, RowDataPacket } from 'mysql2'
import { prepareExecute } from './index.js'

/**
 * 数据库 user 表
 */
// export class UserModel {
//   id?: number
//   userId?: string
//   username?: string
//   password?: string
//   remember?: number
//   createTime?: string
//   updateTime?: string
// }

/**
 * 
 * @param loginInfo 
 */
export const loginDao = async function(loginInfo) {
  const sql = `select * from user where username = ? and password = ?`
  const values = [loginInfo.username, loginInfo.password]
  return await prepareExecute(sql, values)
}

// 更新管理员
export const updateAdminDao = async function(newAccountInfo) {
  const sql = `update user set user_id = ?,username = ?,password = ?,update_time = CURRENT_TIMESTAMP where id = ?`
  const values = [
    newAccountInfo.userId,
    newAccountInfo.username,
    newAccountInfo.password,
    newAccountInfo.id
  ]
  return await prepareExecute(sql, values)
}

